#include <d_bluetooth/bluetooth.h>
#include <d_diag/diag.h>
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-05     donghaomin       the first version
 */
#include "usr_data.h"

errornum buletooth_img_Diag(void* data) {
    d_bule_temp * d_TempHandle = NULL;
    if (data != NULL) {
    } else {
        rt_kprintf("%s,%s,s% error data ponit\n",__FILE__,__FUNCTION__, __LINE__);
        return DIAG_DATA_ERR;
    }
    d_bule_revcmd *d_revbuffer = (d_bule_revcmd *)data;
    switch (d_revbuffer->sub_function_id) {
        case BLUE_TOOTH_CON:
            // 这个位置调用蓝牙的AT指令去查看蓝牙的连接状态
            // 也可以直接去读蓝牙的连接状态

            break;
        case BLUE_TOOTH_LEV:
            // 这个位置调用蓝牙的AT指令去查看蓝牙的连接的信号强度

            break;
        case BLUE_TOOTH_OK:
            d_TempHandle = getTempHandle();
            d_TempHandle->blueTooth_state = bluetooth_AT_COM_CMD(AT_OK_ACK,AT_OK_ANS);
            break;
        default:
            return DIAG_CMD_ERR;
            break;
    }
    return DIAG_OK;
}
errornum temperature_data_Diag(void* data) {
    if (data != NULL) {
    } else {
        rt_kprintf("%s,%s,s% error data ponit\n",__FILE__,__FUNCTION__, __LINE__);
        return DIAG_DATA_ERR;
    }
    d_bule_revcmd *d_revbuffer = (d_bule_revcmd *)data;
    switch (d_revbuffer->sub_function_id) {
        case TEMP_GET:
            // 这个位置就是读取温度值
            break;
        case TEMP_CLEARN:
            // 清除当前机器的所有温度数据值
            dataInit();
            break;
        default:
            return DIAG_CMD_ERR;
            break;
        }
    return DIAG_OK;
}
errornum diagnosis_data_Diag(void* data) {
    if (data != NULL) {
        rt_kprintf("%s,%s,s% error data ponit\n",__FILE__,__FUNCTION__, __LINE__);
    } else {
        return DIAG_DATA_ERR;
    }
    d_bule_revcmd *d_revbuffer = (d_bule_revcmd *)data;
    switch (d_revbuffer->sub_function_id) {
        case TEMP_GET:
            // 这个位置就是读取温度值
            break;
        case TEMP_CLEARN:
            // 清除当前机器的所有温度数据值
            dataInit();
            break;
        default:
            return DIAG_CMD_ERR;
            break;
        }
    return DIAG_OK;
}
/**
 * 一级功能分析
 * */
errornum bule_revdata_Diag(void* data)
{
    errornum ret = DIAG_OK;
    if (data != NULL) {
    } else {
        rt_kprintf("%s,%s,s% error data ponit\n",__FILE__,__FUNCTION__, __LINE__);
        return DIAG_DATA_ERR;
    }
    d_bule_revcmd *d_revbuffer = (d_bule_revcmd *)data;

    if (d_revbuffer->function_id >= FUNCTION_ID_SUM) {
        rt_kprintf("out of range\n");
        return DIAG_OUT_RANGE;
    }

    switch(d_revbuffer->function_id) {
    case BLUE_TOOTH_IMG:
//                HAL_UART_Transmit_IT(&huart2,(uint8_t *)"BLUE_TOOTH_IMG\n",sizeof(d_revbuffer));
        rt_kprintf("BLUE_TOOTH_IMG\n");
        ret = buletooth_img_Diag(data);
        break;

    case TEMP_DATA_OPT:
        rt_kprintf("TEMP_DATA_OPT\n");
        break;

    case DIAG_CODE_OPT:
        rt_kprintf("DIAG_CODE_OPT\n");
        break;
    default:
        return DIAG_CMD_ERR;
        break;
    }
    return ret;
}
